<?php
include 'DBconn.php';
class CompanyMaster
{
    public function getAllCompanies()
    {
        $result=mysql_query("select * from company_header where activestatus=1")or die(mysql_error());
        $res_arr=array();
        while($row=mysql_fetch_object($result))
        {
            $tmp=new VoCompanyMaster();
            $tmp->serialnumber=(int)$row->serialnumber;
            $tmp->company_name=$row->company_name;
            $tmp->company_country=$row->company_country;
            $tmp->company_state=$row->company_state;
            $tmp->company_address1=$row->company_address1;
            $tmp->company_address2=$row->company_address2;
            $tmp->company_zip=$row->company_zip;
            $tmp->company_phone=$row->company_phone;
            $tmp->company_fax=$row->company_fax;
            $tmp->company_email=$row->company_email;
            $tmp->company_url=$row->company_url;
            $tmp->company_regno1=$row->company_regno1;
            $tmp->gst_code=$row->gst_code;
            $tmp->currency_serialnumber=(int)$row->currency_serialnumber;
            $tmp->cre_userid=$row->cre_userid;
            $tmp->cre_datetime=$row->cre_datetime;
            $tmp->activestatus=$row->activestatus;
            $res_arr[]=$tmp;
         }
                   mysql_free_result($result);
    return $res_arr;
    }
    public function addNewCompany($VObject)
    {
        $query="insert into company_header(company_name,company_country,company_state,company_address1,company_address2,company_zip,company_phone,company_fax,company_email,company_url,company_regno1,gst_code,currency_serialnumber,cre_userid,cre_datetime,activestatus) values('$VObject->company_name','$VObject->company_country','$VObject->company_state','$VObject->company_address1','$VObject->company_address2','$VObject->company_zip','$VObject->company_phone','$VObject->company_fax','$VObject->company_email','$VObject->company_url','$VObject->company_regno1','$VObject->gst_code','$VObject->currency_serialnumber','$VObject->cre_userid','$VObject->cre_datetime',1)";
        $s=mysql_query($query)or die(mysql_error());
        if ($s=1) 
      {
        mysql_query("COMMIT");
      }
      else
      {
        mysql_query("ROLLBACK");
      }
      return $this->getAllCompanies();
    }
    public function deleteCompany($VObject)
    {
        $query="update company_header set activestatus=0 where serialnumber=".$VObject->serialnumber;
         $s=mysql_query($query)or die(mysql_error());
        if ($s=1) 
      {
        mysql_query("COMMIT");
      }
      else
      {
        mysql_query("ROLLBACK");
      }
      return $this->getAllCompanies();
        
    }
    public function editCompany($VObject)
    {
        $query="update company_header set company_name='$VObject->company_name',company_country='$VObject->company_country',company_state='$VObject->company_state',company_address1='$VObject->company_address1',company_address2='$VObject->company_address2',company_zip='$VObject->company_zip',company_phone='$VObject->company_phone',company_fax='$VObject->company_fax',company_email='$VObject->company_email',company_url='$VObject->company_url',company_regno1='$VObject->company_regno1',gst_code='$VObject->gst_code',currency_serialnumber='$VObject->currency_serialnumber',cre_userid='$VObject->cre_userid',cre_datetime='$VObject->cre_datetime' where serialnumber='$VObject->serialnumber'";
         $s=mysql_query($query)or die(mysql_error());
        if ($s=1) 
      {
        mysql_query("COMMIT");
      }
      else
      {
        mysql_query("ROLLBACK");
      }
      return $this->getAllCompanies();
    }
}
//$vo=new VoCompanyMaster();
//$vo->serialnumber=3;
//$vo->company_name="abc pvt ltd";
//$vo->company_country="INDIA";
//$vo->currency_serialnumber=1;
//$vo->cre_userid=31;
//$s=new companyMaster;
//echo $s->editCompany($vo);
class VoCompanyMaster
{
    var $serialnumber;
    var $company_name;
    var $company_country;
    var $company_state;
    var $company_address1;
    var $company_address2;
    var $company_zip;
    var $company_phone;
    var $company_fax;
    var $company_email;
    var $company_url;
    var $company_regno1;
    var $gst_code;
    var $currency_serialnumber;
    var $cre_userid;
    var $cre_datetime;
    var $activestatus;
    }

?>